
//@require @packageOverrides
Ext.Loader.setConfig({
	enabled : true
});

/*******************************************************************************
 * 当前登录用户
 */
var loginUser, treeNodes;

(function() {
	var queryCurrentInfo = function() {
		// Ajax请求当前登录用户信息
		Ext.Ajax.request({
			url : './rs/user/currentUserInfo',
			method: 'POST',
			jsonData: {},
			async : false,
			success : function(response, opts) {
				var result = Ext.decode(response.responseText);
				// 设置当前登录用户信息
				loginUser = result.userInfo;
				// 设置当前登录用户菜单信息
				treeNodes = result.treeNodes;
			}
		});
	};
	queryCurrentInfo();
})();

Ext.define('CurrentUser', {
	singleton : true,
	
	//当前登录用户对象
	getCurrentUser : function() {
		if (!Ext.isEmpty(loginUser)) {
			return loginUser;
		}
	},
	//当前登录用户的用户名
	getRealName : function() {
		if (!Ext.isEmpty(loginUser)) {
			return CurrentUser.getCurrentUser().realName;
		}
	},
	//当前登录用户的用户名
	getLoginAccount : function() {
		if (!Ext.isEmpty(loginUser)) {
			return CurrentUser.getCurrentUser().loginAccount;
		}
	},
	//当前登录用户菜单
	getUserMenus: function(){
		if(!Ext.isEmpty(loginUser)){
			return treeNodes;
		}
	}
});

Ext.define('SystemUtil', {
	singleton: true,
	getImageUrl: function(url, type){
		if(Ext.isEmpty(url)){
			return url;
		}
		var strs = url.split('.jpg');
		if(strs.length==2){
			return Common.config.RESOURCE_URL + strs[0] + type + '.jpg' + "?v=" + new Date().getTime();		
		}
		strs = url.split('.png');
		if(strs.length==2){
			return Common.config.RESOURCE_URL + strs[0] + type + '.png' + "?v=" + new Date().getTime();
		}
		strs = url.split('.gif');
		if(strs.length==2){
			return Common.config.RESOURCE_URL + strs[0] + type + '.gif' + "?v=" + new Date().getTime();
		}
		strs = url.split('.bmp');
		if(strs.length==2){
			return Common.config.RESOURCE_URL + strs[0] + type + '.bmp' + "?v=" + new Date().getTime();
		}
		return url;
	},
	getOrderAutoLoadTime: function(){
		return orderAutoLoadTime;
	},
	getSubCommissionBase: function(){
		return subCommissionBase;
	},
	// UUID,len是生成UUID的长度
	getUUID : function(len, radix) {
		var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
				.split('');
		var uuid = [], i;
		radix = radix || chars.length;
		if (len) {
			for (i = 0; i < len; i++)
				uuid[i] = chars[0 | Math.random() * radix];
		} else {
			var r;
			uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
			uuid[14] = '4';
			for (i = 0; i < 36; i++) {
				if (!uuid[i]) {
					r = 0 | Math.random() * 16;
					uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
				}
			}
		}
		return uuid.join('');
	}
});

Ext.application({
	autoCreateViewport : true,
	name : 'MyApp'
});
Ext.QuickTips.init();